What is heimdalljs-logger?
heimdalljs-logger is a logging utility designed to work with the heimdalljs performance monitoring library. It provides a simple and efficient way to log messages with different levels of severity, making it easier to track and debug performance issues in your application.
What are heimdalljs-logger's main functionalities?
Basic Logging
Allows you to log messages with different levels of severity (info, warn, error).
const logger = require('heimdalljs-logger')('my-app');
logger.info('This is an info message');
logger.warn('This is a warning message');
logger.error('This is an error message');
Custom Log Levels
Enables you to define custom log levels for more granular control over logging.
const logger = require('heimdalljs-logger')('my-app');
logger.addLevel('debug', 1000);
logger.debug('This is a debug message');
Contextual Logging
Allows you to add contextual information to your log messages, making it easier to understand the context in which a log message was generated.
const logger = require('heimdalljs-logger')('my-app');
logger.info('Starting process', { processId: 12345 });
Other packages similar to heimdalljs-logger
winston
Winston is a versatile logging library with support for multiple transports (e.g., console, file, HTTP). It offers more advanced features like log formatting, log levels, and custom transports, making it a more comprehensive solution compared to heimdalljs-logger.
bunyan
Bunyan is a simple and fast JSON logging library. It provides a straightforward API for logging and includes features like log levels, serializers, and log rotation. Bunyan's focus on JSON logging makes it a good choice for structured logging, which is not a primary focus of heimdalljs-logger.
pino
Pino is a low-overhead logging library designed for high-performance applications. It offers features like log levels, serializers, and log redirection. Pino's emphasis on performance and low overhead makes it a suitable alternative to heimdalljs-logger for applications where logging performance is critical.
Usage
With no Heimdall Tree
var logger = require('heimdalljs-logger')('foo');
logger.trace('trace message');
logger.debug('debug message');
logger.info('info message');
logger.warn('warn message');
logger.error('error message');
console.log('app message');
DEBUG=foo DEBUG_LEVEL=trace foo
foo
DEBUG=foo DEBUG_LEVEL=warn foo
With a Heimdall Tree
var heimdall = require('heimdalljs');
var config = require('heimdalljs').configFor('logging');
config.matcher = (id) => /hai/.test(id.name);
config.depth = 2;
var logger = require('heimdalljs-logger')('foo');
heimdall.start('a');
heimdall.start('bhai');
heimdall.start('c');
heimdall.start('dhai');
logger.warn('warn message');